#include "StdAfx.h"
#include "ShowStrategy.h"
#include <iostream>
#include "CmutaAlgoDemo.h"

CShowStrategy::CShowStrategy(void)
{
}

CShowStrategy::~CShowStrategy(void)
{
}

void CShowStrategy::ShowOutput()
{
	do 
	{
		CString strCommandName("");
		GetInputStr(strCommandName);
		if(ExitPro(strCommandName))
			return;

		CmutaAlgoDemo strMuta;
		while(!strMuta.ShowCommondResult(strCommandName))
		{
			AssertMes();
			GetInputStr(strCommandName);
			if(ExitPro(strCommandName))
				break;
		}
	} while (IsRunNextCommand());
}

bool CShowStrategy::IsRunNextCommand()
{
	ReRunMsg();
	CString strCommandName("");
	GetInputStr(strCommandName);
	if(strCommandName == "y")
		return true;
	if(strCommandName == "n")
		return false;
	return true;
}

void CShowStrategy::ReRunMsg()
{
	cout << "Is run next command?(y/n)!" << endl;
}

bool CShowStrategy::ExitPro(const CString& strCommandName)
{
	if(strCommandName == "exit")
		return true;
	else
		return false;
}

void CShowStrategy::GetInputStr(CString& strOutput)
{
	char ch[1024];
	cin.getline(ch,1024);
	strOutput.Empty();
	CString strTmp(ch,1024);
	strOutput = strTmp;
	return ;
}

void CShowStrategy::AssertMes()
{
	cout << "Please try it again!" << endl;
	return ;
}

